import serial
import time
ser = serial.Serial('/dev/ttyAMA1', 115200)
if ser.isOpen == False:
    ser.open()          # 打开串口
ser.write(b"hello stm32!!\n")
try:
    while True:
        size = ser.inWaiting()  	# 获得缓冲区字符
        if size != 0:
            res = ser.read(size)   	# 读取内容并显示
            print(res)
            ser.flushInput()		# 情况接收缓存区
            time.sleep(0.5)			# 软件延时
except KeyboardInterrupt:
    ser.close()
